<?php

/*
 * litchicms
 * Copyright (C) 2010-6-13 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");


$can_action = array('from', 'update');

if (empty($_POST['action']) || !in_array($_POST['action'], $can_action)) {
    $_POST['action'] = 'from';
}


switch ($_POST['action']) {
    case 'from':

        break;

    case 'update':
        !key_exists('field', $_POST) && exit("NO POST FIELD");
        !is_array($_POST['field']) && exit("POST FIELD NOT IS A ARRAY");
        foreach ($BRK_GLOBAL['ComponentValidationFunction'] as $v) {
            if (($temp = call_user_func($v)) !== TRUE) {
                eMsg(0, '修改 ' . $COLLECTION_CNAME . ' 失败', array(1, '?' . bgpre()));
                eMsg(0, $temp);
                break 2;
            }
        }

        foreach ($COLLECTION_DATA as $k => $v) {
            $dataarr = array(
                'collection_key' => $k,
                'collection_value' => $v['data_type'] == 'array' ? addslashes(serialize(brk_stripslashes($_POST['field'][$k]))) : $_POST['field'][$k]
            );
            brk_update('simple_collection', $dataarr, "WHERE collection_id='$COLLECTION_ID' AND collection_key='$k'");
        }


        foreach ($BRK_GLOBAL['ComponentEndingFunction'] as $v) {
            if (($temp = call_user_func($v)) !== TRUE) {
                eMsg(0, '修改 ' . $COLLECTION_CNAME . ' 失败', array(1, '?' . bgpre()));
                eMsg(0, $temp);
                break 2;
            }
        }

        eMsg(1, '修改 ' . $COLLECTION_CNAME . ' 成功', array(1, '?' . bgpre()));

        break;

    default:
        break;
}
?>